<template>
  <div id="topplaylist">
    <!-- 头部区域 -->
    <div class="head"></div>
    <div class="label">
      <span class="label1">每日推荐</span>
      <span class="label2">人生就像一杯茶，不会苦一辈子，但总会苦一阵子。</span>
    </div>
    <!-- 推荐列表 -->
    <div class="dayli">
      <!-- <info-icon :parentmsg="recommend" v-for="item in recommend" :key="item.id"></info-icon> -->
      <!-- <div class="infoIcon" v-for="item in recommend.slice(0,12)" :key="item.id"> -->
      <div class="infoIcon" v-for="info in playlist" :key="info.id">
        <div class="img">
          <img v-lazy="info.coverImgUrl" alt @click="getListId(info.id)" />
        </div>
        <div class="recommend-name">
          <div class="mask"></div>
          <div class="van-ellipsis" v-text="info.name"></div>
        </div>
      </div>
    </div>
    <!-- 分页 -->
    <van-pagination
      v-model="currentPage"
      :total-items="total_item"
      :items-per-page="30"
      :show-page-size="4"
      force-ellipses
      @change="changePage"
    />
  </div>
</template>

<script>
export default {
  data: function() {
    return {
      limit: "30",
      playlist: [],
      currentPage: "1",
      total_item: ""
    };
  },
  created() {
    //   获取推荐歌单列表
    this.$http.get("top/playlist?limit=" + this.limit).then(result => {
      console.log(result);
      this.playlist = result.data.playlists;
      this.total_item = result.data.total;
    });
  },
  methods: {
    getListId(id) {
      this.$router.push("/PlayList/" + id);
    },
    //改变页码时触发
    changePage() {
      //回到页面开头
      document.documentElement.scrollTop = 0;
      // 请求下一页
      this.$http
        .get(
          "top/playlist?limit=" +
            this.limit +
            "&offset=" +
            (this.currentPage - 1) * this.limit
        )
        .then(result => {
          console.log(result);
          this.playlist = result.data.playlists;
          this.total_item = result.data.total;
        });
    }
  }
};
</script>

<style lang="scss">
#topplaylist {
  .head {
    width: 100%;
    height: 200px;
    background-image: url("../images/label/default.jpeg");
    background-size: 100%;
    background-position: center;
    filter: brightness(0.7);
  }
  .label {
    color: white;
    .label1 {
      font-size: 35px;
      position: absolute;
      top: 60px;
    }
    .label2 {
      font-size: 14px;
      position: absolute;
      top: 220px;
      right: 0;
      left: 0;
    }
  }

  .dayli {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    overflow: scroll;

    padding: 5% 8% 0 8%;
    .infoIcon {
      width: 44%;
      margin: 15px 0;
      border-radius: 8px;
      box-shadow: 3px 3px 10px 3px #eee;
      font-size: 2px;
      img {
        width: 100%;
        border-radius: 8px;
      }
      //遮罩样式
      .mask {
        height: 30px;
        width: 100%;
        margin-top: -30px;
        background: rgba(255, 255, 255, 0.5);
        filter: blur(25px);
        filter: brightness(0.8);
        position: relative;
      }
      .recommend-name {
        .van-ellipsis {
          margin-top: -30px;
          position: relative;
          font-size: 12px;
          color: rgb(255, 255, 255);
          padding: 5px 10px;
        }
      }
    }
  }
}
</style>